package com.xucy.springboot.common;

/**
 * @Author xucy
 * @Date 2019-03-26 19:31
 * @Description 自创栈
 **/

public class MyStack {

    long[] arr;
    int top = -1;

    MyStack() {
        arr = new long[10];
    }

    MyStack(int i) {
        arr = new long[i];
    }

    /**
     * 向栈中添加数据
     *
     * @param
     * @return
     * @Author xucy
     * @Date 19:32 2019-03-26
     */
    public void push(long val) {
        arr[++top] = val;
    }

    /**
     * 移除数据
     *
     * @param
     * @return
     * @Author xucy
     * @Date 19:34 2019-03-26
     */
    public long pop() {
        return arr[top--];
    }

    /**
     * 查看栈是否已经满了
     *
     * @param
     * @return
     * @Author xucy
     * @Date 19:35 2019-03-26
     */
    public boolean isFull() {
        return top == arr.length - 1;
    }

    /**
     * 查看栈是否为空
     *
     * @param
     * @return
     * @Author xucy
     * @Date 19:35 2019-03-26
     */
    public boolean isEmpty() {
        return top == -1;
    }

    public static void main(String[] args) {
        MyStack myStack = new MyStack(4);
        myStack.push(3);
        myStack.push(25);
        myStack.push(12);
        myStack.push(-3);

        while (!myStack.isEmpty()) {
            System.out.print(myStack.pop() + ",");
        }
    }
}
